/**
 * Copyright (c) 2010 deniskir@gmail.com. All rights reserved.
 *
 * @author Denis Kiriusin
 */

package com.dksoftware.combo;


// immutable Builder object
// TODO: add lastModified? headers Map?
//TODO test this object
class RequestDetails {

	// MIME content types
	// TODO: do we need them here???
	// TODO: equals(), hashcode()

	enum Type {
		css("text/css"), js("text/javascript");

		private final String mime;

		Type(String mime) {
	        this.mime = mime;
	    }

		public String getMime() {
			return mime;
		}
	}
	
	final Type type;
	final long version;
	final String theme;
	final String resources;
	final String extension;
	final String mimeType;
	
	public static class Builder {
		// required parameters
		private final Type type;
		// optional parameters initialised
		private String theme = null;
		private String resources = null;
		private long version = 0;
		
		public Builder(Type type) {
			this.type = type;
		}
		
		public Builder theme(String val) {
			theme = val;
			return this;
		}
		public Builder resources(String val) {
			resources = val;
			return this;
		}
		public Builder version(long val) {
			version = val;
			return this;
		}
		
		public RequestDetails build() {
			return new RequestDetails(this);
		}
	}
	
	private RequestDetails(Builder builder) {
		this.type = builder.type;
		this.version = builder.version;
		this.theme = builder.theme;
		this.resources = builder.resources;
		this.extension = this.type == Type.css ? "css" : "js";
		this.mimeType = this.type == Type.css ? Type.css.getMime() : Type.js.getMime();
	}
	
	
	// Overridden methods

	@Override
	public String toString() {
		return "RequestDetails [type=" + type + ", version=" + version
				+ ", theme=" + theme + ", resources=" + resources
				+ ", extension=" + extension + ", mimeType=" + mimeType + "]";
	}
}
